#ifndef ACAPELLA_SYNCHRONIZE_MUTEX_COND_WINDOWS_CONDITION_VARIABLE_HPP
#define ACAPELLA_SYNCHRONIZE_MUTEX_COND_WINDOWS_CONDITION_VARIABLE_HPP

#include <windows.h>

namespace acapella
{
namespace synchronize
{

class mutex_cond
{
public:
	mutex_cond()
	{
		::InitializeCriticalSection(&cs_);
		::InitializeConditionVariable(&cv_);
	}

	~mutex_cond()
	{
		::DeleteCriticalSection(&cs_);
	}

	int wait()
	{
		return ::SleepConditionVariableCS(&cv_, &cs_, INFINITE) == TRUE ? 0 : -1;
	}

	int wait(_uint32_ timeout)
	{
		return ::SleepConditionVariableCS(&cv_, &cs_, timeout) == TRUE ? 0 : -1;
	}

	int signal()
	{
		WakeConditionVariable(&cv_);
		return 0;
	}

	int boardcast()
	{
		WakeAllConditionVariable(&cv_);
		return 0;
	}

private:
	CRITICAL_SECTION  cs_;
	CONDITION_VARIABLE cv_;

	mutex_cond(const mutex_cond&);
	mutex_cond& operator=(const mutex_cond&);
};


}
}


#endif

